package com.tianyang.yukuaifuzs.jump.jsbridge;


import com.tianyang.yukuaifuzs.base.BaseActivity;
import com.tianyang.yukuaifuzs.business.main.view.MainActivity;
import com.tianyang.yukuaifuzs.jump.jsbridge.module.JBCallback;
import com.tianyang.yukuaifuzs.jump.jsbridge.module.JSBridgeMethod;
import com.tianyang.yukuaifuzs.jump.jsbridge.module.JsModule;
import com.tianyang.yukuaifuzs.utils.AppContextUtil;
import com.tianyang.yukuaifuzs.utils.IntentTool;

/**
 * Description：H5接口调用
 * Created by 薛勇军 on 2018/6/11.
 */

public class ServiceModule extends JsModule {

    @Override
    public String getModuleName() {
        return "service";
    }

    @JSBridgeMethod(methodName = "back")
    public void back(String msg, final JBCallback success, final JBCallback failure) {
        if (getContext() instanceof BaseActivity) {
            ((BaseActivity) getContext()).onBackPressed();
        }
    }

    @JSBridgeMethod(methodName = "finish")
    public void finish(String msg, final JBCallback success, final JBCallback failure) {
        if (getContext() instanceof BaseActivity) {
            ((BaseActivity) getContext()).finish();
        }
    }

    @JSBridgeMethod(methodName = "home")
    public void home(String msg, final JBCallback success, final JBCallback failure) {
        if (getContext() instanceof BaseActivity) {
            ((BaseActivity) getContext()).finish();
            AppContextUtil.finishAllExclByActivity(MainActivity.class.getName());
            IntentTool.startActivity(mContext, MainActivity.class);
        }
    }

    @JSBridgeMethod(methodName = "backToHomePage")
    public void backToHomePage(String title, final JBCallback success, final JBCallback failure) {
        if (getContext() instanceof BaseActivity) {
            ((BaseActivity) getContext()).finish();
        }
    }
}
